package com.cloud.user.controller;

import com.cloud.user.config.PatternProperties;
import com.cloud.user.entity.User;
import com.cloud.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/user")
// @RefreshScope // 在value注解所在的类上添加，实现nacos配置热更新
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private PatternProperties patternProperties;

//    @Value("${pattern.dateformat}")
//    private String dateformat;

    @GetMapping("/getUser/{userId}")
    public User queryById(@PathVariable("userId") Long userId, @RequestHeader(value = "Honest", required = false) String requestHeaderHonest) {
        System.out.println(requestHeaderHonest);
        return userService.queryById(userId);
    }

    @GetMapping("/now")
    public String getNow() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(patternProperties.getDateformat()));
    }

    @GetMapping("prop")
    public PatternProperties getPatternProperties() {
        return patternProperties;
    }
}
